home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Magazine / Online / OpenURL / Developer / Source / prefs_app.c < prev    next >
C/C++ Source or Header  |  1999-09-26  |  2KB  |  96 lines

  1. /*
  2. ** OpenURL - MUI preferences for openurl.library
  3. ** Written by Troels Walsted Hansen <troels@thule.no>
  4. ** Placed in the public domain.
  5. **
  6. ** This module contains the code to the App Application.mui subclass.
  7. */
  8.  
  9. #include "prefs_common.h"
  10. #include "prefs_main.h"
  11. #include "prefs_app.h"
  12.  
  13. /**************************************************************************/
  14.  
  15. static ULONG mOpenWin (struct IClass *cl, Object *obj, struct MUIP_App_OpenWin *msg);
  16. static ULONG mCloseWin(struct IClass *cl, Object *obj, struct MUIP_App_CloseWin *msg);
  17.  
  18. static Object *FindWinObjByAttr(Object *app, ULONG attr, ULONG val);
  19.  
  20. /**************************************************************************/
  21.  
  22. static ULONG mOpenWin(struct IClass *cl, Object *obj, struct MUIP_App_OpenWin *msg)
  23. {
  24.     Object *win = FindWinObjByAttr(obj, msg->IDAttr, msg->IDVal);
  25.  
  26.     if(!win)
  27.     {
  28.         win = NewObject(msg->Class, NULL, 
  29.                         msg->IDAttr, msg->IDVal,
  30.                         TAG_MORE, &msg->InitAttrs);
  31.  
  32.         if(win)
  33.             DoMethod(obj, OM_ADDMEMBER, win);
  34.         else 
  35.         {
  36.             DisplayBeep(NULL);
  37.             return(FALSE);
  38.         }
  39.     }
  40.  
  41.     set(win, MUIA_Window_Open, TRUE);
  42.     return((ULONG)xget(win, MUIA_Window_Open));
  43. }
  44.  
  45. /**************************************************************************/
  46.  
  47. static ULONG mCloseWin(struct IClass *cl, Object *obj, struct MUIP_App_CloseWin *msg)
  48. {
  49.     Object *win = FindWinObjByAttr(obj, msg->IDAttr, msg->IDVal);
  50.  
  51.     if(win)
  52.     {
  53.         set(win, MUIA_Window_Open, FALSE);
  54.         DoMethod(obj, OM_REMMEMBER, win);
  55.         MUI_DisposeObject(win);
  56.     }
  57.  
  58.     return(TRUE);
  59. }
  60.  
  61. /**************************************************************************/
  62.  
  63. SAVEDS ASM ULONG App_Dispatcher(REG(a0) struct IClass *cl, REG(a2) Object *obj, REG(a1) Msg msg)
  64. {
  65.     switch(msg->MethodID)
  66.     {
  67.         case MUIM_App_OpenWin : return(mOpenWin (cl,obj,(APTR)msg));
  68.         case MUIM_App_CloseWin: return(mCloseWin(cl,obj,(APTR)msg));
  69.     }
  70.  
  71.     return(DoSuperMethodA(cl,obj,msg));
  72. }
  73.  
  74. /**************************************************************************/
  75.  
  76. static Object *FindWinObjByAttr(Object *app, ULONG attr, ULONG val)
  77. {
  78.     struct List *winlist;
  79.     Object *obj;
  80.     APTR state;
  81.  
  82.     /* return the window object which supports OM_GET on attr, and 
  83.        whose value of attr == val */
  84.  
  85.     get(app, MUIA_Application_WindowList, &winlist);
  86.     state = winlist->lh_Head;
  87.  
  88.     while(obj = NextObject(&state))
  89.     {
  90.         ULONG value;
  91.         if(get(obj, attr, &value) && (value == val)) break;
  92.     }
  93.  
  94.     return(obj);
  95. }
  96.